﻿using System;
using UnityEngine;
using UnityEngine.EventSystems;

// Token: 0x02000063 RID: 99
public class GuideDriveManager : MonoBehaviour
{
	// Token: 0x17000038 RID: 56
	// (get) Token: 0x06000328 RID: 808 RVA: 0x00014978 File Offset: 0x00012B78
	// (set) Token: 0x06000329 RID: 809 RVA: 0x00014980 File Offset: 0x00012B80
	public bool enablePos { get; private set; }

	// Token: 0x17000039 RID: 57
	// (get) Token: 0x0600032A RID: 810 RVA: 0x0001498C File Offset: 0x00012B8C
	// (set) Token: 0x0600032B RID: 811 RVA: 0x00014994 File Offset: 0x00012B94
	public bool enableRot { get; private set; }

	// Token: 0x1700003A RID: 58
	// (get) Token: 0x0600032C RID: 812 RVA: 0x000149A0 File Offset: 0x00012BA0
	// (set) Token: 0x0600032D RID: 813 RVA: 0x000149A8 File Offset: 0x00012BA8
	public bool enableScl { get; private set; }

	// Token: 0x1700003B RID: 59
	// (get) Token: 0x0600032E RID: 814 RVA: 0x000149B4 File Offset: 0x00012BB4
	public Transform Target
	{
		get
		{
			return this.target;
		}
	}

	// Token: 0x1700003C RID: 60
	// (get) Token: 0x0600032F RID: 815 RVA: 0x000149BC File Offset: 0x00012BBC
	// (set) Token: 0x06000330 RID: 816 RVA: 0x000149C4 File Offset: 0x00012BC4
	public bool IsActive
	{
		get
		{
			return this.isActive;
		}
		set
		{
			if (this.isActive != value)
			{
				this.isActive = value;
				this.ChangeActiveObj();
			}
		}
	}

	// Token: 0x1700003D RID: 61
	// (get) Token: 0x06000331 RID: 817 RVA: 0x000149E0 File Offset: 0x00012BE0
	public GuideDrive MovingDrive
	{
		get
		{
			return this.movingDrive;
		}
	}

	// Token: 0x06000332 RID: 818 RVA: 0x000149E8 File Offset: 0x00012BE8
	private void Awake()
	{
		this.drives = base.GetComponentsInChildren<GuideDrive>();
		this.isActive = false;
	}

	// Token: 0x06000333 RID: 819 RVA: 0x00014A00 File Offset: 0x00012C00
	public void SetManager(GuidesManager manager)
	{
		this.manager = manager;
	}

	// Token: 0x06000334 RID: 820 RVA: 0x00014A0C File Offset: 0x00012C0C
	private void Start()
	{
		this.ChangeActiveObj();
	}

	// Token: 0x06000335 RID: 821 RVA: 0x00014A14 File Offset: 0x00012C14
	private void Update()
	{
	}

	// Token: 0x06000336 RID: 822 RVA: 0x00014A18 File Offset: 0x00012C18
	private void LateUpdate()
	{
		this.Update_PlanePos();
		this.ScaleCalc();
		if (this.movingDrive != null)
		{
			this.InvokeTransform();
		}
		if (!this.MoveInitiative)
		{
			base.transform.position = this.target.position;
			this.rotRoot.rotation = this.target.transform.rotation;
		}
	}

	// Token: 0x06000337 RID: 823 RVA: 0x00014A84 File Offset: 0x00012C84
	public GuideDriveManager.CursorCheckData CursorCheck()
	{
		GuideDriveManager.CursorCheckData result;
		result.distance = float.MaxValue;
		result.drive = null;
		result.pos = Vector3.zero;
		bool flag = EventSystem.current && EventSystem.current.IsPointerOverGameObject();
		if (flag)
		{
			return result;
		}
		Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		float num = float.MaxValue;
		RaycastHit raycastHit;
		if (this.IsActive)
		{
			if (this.movingDrive == null)
			{
				GuideDrive guideDrive = null;
				Vector3 pos = Vector3.zero;
				foreach (GuideDrive guideDrive2 in this.drives)
				{
					if (guideDrive2.GetComponent<Collider>().Raycast(ray, out raycastHit, this.checkDis) && raycastHit.distance < num)
					{
						guideDrive = guideDrive2;
						num = raycastHit.distance;
						pos = raycastHit.point;
					}
				}
				if (guideDrive != null)
				{
					result.distance = num;
					result.drive = guideDrive;
					result.pos = pos;
					return result;
				}
			}
		}
		else if (this.sphere.GetComponent<Collider>().Raycast(ray, out raycastHit, this.checkDis))
		{
			result.distance = raycastHit.distance;
			result.drive = this.sphere;
			result.pos = raycastHit.point;
			return result;
		}
		return result;
	}

	// Token: 0x06000338 RID: 824 RVA: 0x00014BF4 File Offset: 0x00012DF4
	public void SetOutCursor()
	{
		this.sphere.OnCursor = false;
		foreach (GuideDrive guideDrive in this.drives)
		{
			guideDrive.OnCursor = false;
		}
	}

	// Token: 0x06000339 RID: 825 RVA: 0x00014C34 File Offset: 0x00012E34
	public void SetOnCursor(GuideDrive drive)
	{
		this.SetOutCursor();
		drive.OnCursor = true;
	}

	// Token: 0x0600033A RID: 826 RVA: 0x00014C44 File Offset: 0x00012E44
	private void InvokeTransform()
	{
		if (this.manager != null)
		{
			if (this.target != null)
			{
				this.manager.OnChangeTransform(this.target.transform);
			}
			else
			{
				this.manager.OnChangeTransform(this.rotRoot.transform);
			}
		}
	}

	// Token: 0x0600033B RID: 827 RVA: 0x00014CA4 File Offset: 0x00012EA4
	public void OnMoveStart(GuideDrive drive)
	{
		this.movingDrive = drive;
		this.manager.activeGuide = this;
	}

	// Token: 0x0600033C RID: 828 RVA: 0x00014CBC File Offset: 0x00012EBC
	public void OnMoveEnd(GuideDrive drive)
	{
		this.manager.activeGuide = null;
		this.movingDrive = null;
	}

	// Token: 0x0600033D RID: 829 RVA: 0x00014CD4 File Offset: 0x00012ED4
	public void SetTrans(Vector3 pos, Quaternion rot, Vector3 scl, bool invoke)
	{
		base.transform.position = pos;
		this.rotRoot.rotation = rot;
		this.sclRoot.rotation = rot;
		if (this.MoveInitiative && this.target != null)
		{
			this.target.transform.position = pos;
			this.target.transform.rotation = rot;
			this.target.transform.localScale = scl;
		}
		if (invoke && this.delegateSetTrans != null)
		{
			this.delegateSetTrans(pos, rot, scl);
		}
	}

	// Token: 0x0600033E RID: 830 RVA: 0x00014D74 File Offset: 0x00012F74
	public void SetLocalTrans(Vector3 pos, Quaternion rot, Vector3 scl, bool invoke)
	{
		bool flag = false;
		if (this.MoveInitiative && this.target != null)
		{
			this.target.transform.localPosition = pos;
			this.target.transform.localRotation = rot;
			this.target.transform.localScale = scl;
			flag = true;
		}
		if (flag)
		{
			base.transform.position = this.target.transform.position;
			base.transform.localRotation = Quaternion.identity;
			this.rotRoot.rotation = this.target.transform.rotation;
			this.sclRoot.rotation = this.target.transform.rotation;
		}
		else
		{
			base.transform.localPosition = pos;
			base.transform.localRotation = Quaternion.identity;
			this.rotRoot.localRotation = rot;
			this.sclRoot.localRotation = rot;
		}
		if (invoke && this.delegateSetTrans != null)
		{
			this.delegateSetTrans(base.transform.position, this.rotRoot.rotation, scl);
		}
	}

	// Token: 0x0600033F RID: 831 RVA: 0x00014EA8 File Offset: 0x000130A8
	public void SetTrans(Transform trans, bool invoke)
	{
		this.SetTrans(trans.position, trans.rotation, trans.localScale, invoke);
	}

	// Token: 0x06000340 RID: 832 RVA: 0x00014EC4 File Offset: 0x000130C4
	public void SetTarget(Transform target)
	{
		this.target = target;
		this.SetTrans(target.transform, false);
	}

	// Token: 0x06000341 RID: 833 RVA: 0x00014EDC File Offset: 0x000130DC
	private void ChangeActiveObj()
	{
		this.ChangeEnable();
		bool flag = this.enablePos | this.enableRot | this.enableScl;
		this.sphere.gameObject.SetActive(!this.isActive && flag);
		if (this.isActive)
		{
			this.manager.Activate(this);
			this.InvokeTransform();
		}
	}

	// Token: 0x06000342 RID: 834 RVA: 0x00014F40 File Offset: 0x00013140
	private void ChangeEnable()
	{
		foreach (GuideDrive_Pos guideDrive_Pos in this.drivePos)
		{
			guideDrive_Pos.gameObject.SetActive(this.isActive && this.enablePos);
		}
		foreach (GuideDrive_Pos guideDrive_Pos2 in this.drivePlane)
		{
			guideDrive_Pos2.gameObject.SetActive(this.isActive && this.enablePos);
		}
		foreach (GuideDrive_Rot guideDrive_Rot in this.driveRot)
		{
			guideDrive_Rot.gameObject.SetActive(this.isActive && this.enableRot);
		}
		foreach (GuideDrive_Scl guideDrive_Scl in this.driveScl)
		{
			guideDrive_Scl.gameObject.SetActive(this.isActive && this.enableScl);
		}
	}

	// Token: 0x06000343 RID: 835 RVA: 0x00015064 File Offset: 0x00013264
	public void DriveMovePosition(Vector3 move)
	{
		if (this.delegateMovePos != null)
		{
			this.delegateMovePos(move);
		}
		if (this.MoveInitiative)
		{
			base.transform.position += move;
			if (this.target != null)
			{
				this.target.position = base.transform.position;
			}
		}
	}

	// Token: 0x06000344 RID: 836 RVA: 0x000150D4 File Offset: 0x000132D4
	public void DriveMoveRotation(Quaternion move)
	{
		if (this.delegateMoveRot != null)
		{
			this.delegateMoveRot(move);
		}
		if (this.MoveInitiative)
		{
			this.rotRoot.rotation *= move;
			this.sclRoot.rotation *= move;
			if (this.target != null)
			{
				this.target.rotation = this.rotRoot.rotation;
			}
		}
	}

	// Token: 0x06000345 RID: 837 RVA: 0x00015158 File Offset: 0x00013358
	public void DriveMoveScale(Vector3 move)
	{
		if (this.delegateMoveScl != null)
		{
			this.delegateMoveScl(move);
		}
		if (this.MoveInitiative && this.target != null)
		{
			this.target.localScale += move;
		}
	}

	// Token: 0x06000346 RID: 838 RVA: 0x000151B0 File Offset: 0x000133B0
	private void ScaleCalc()
	{
		float num = Vector3.Distance(base.transform.position, Camera.main.transform.position);
		float num2 = num * this.scaleRate;
		base.transform.localScale = new Vector3(num2, num2, num2);
	}

	// Token: 0x06000347 RID: 839 RVA: 0x000151FC File Offset: 0x000133FC
	public void SetEnables(bool pos, bool rot, bool scl)
	{
		this.enablePos = pos;
		this.enableRot = rot;
		this.enableScl = scl;
		this.ChangeEnable();
	}

	// Token: 0x06000348 RID: 840 RVA: 0x0001521C File Offset: 0x0001341C
	public void Update_PlanePos()
	{
		float num = 0.05f;
		Vector3 vector = Camera.main.transform.position - base.transform.position;
		foreach (GuideDrive_Pos guideDrive_Pos in this.drivePlane)
		{
			Vector3 localPosition = guideDrive_Pos.transform.localPosition;
			if (guideDrive_Pos.moveType == GuideDrive_Pos.MoveType.XY)
			{
				localPosition.x = ((vector.x < 0f) ? (-num) : num);
				localPosition.y = ((vector.y < 0f) ? (-num) : num);
			}
			else if (guideDrive_Pos.moveType == GuideDrive_Pos.MoveType.XZ)
			{
				localPosition.x = ((vector.x < 0f) ? (-num) : num);
				localPosition.z = ((vector.z < 0f) ? (-num) : num);
			}
			else if (guideDrive_Pos.moveType == GuideDrive_Pos.MoveType.YZ)
			{
				localPosition.y = ((vector.y < 0f) ? (-num) : num);
				localPosition.z = ((vector.z < 0f) ? (-num) : num);
			}
			guideDrive_Pos.transform.localPosition = localPosition;
		}
	}

	// Token: 0x06000349 RID: 841 RVA: 0x0001537C File Offset: 0x0001357C
	public void SetDelegate(GuideDriveManager.DelegateMovePos pos, GuideDriveManager.DelegateMoveRot rot, GuideDriveManager.DelegateMoveScl scl, GuideDriveManager.DelegateSetTrans trans)
	{
		this.delegateMovePos = pos;
		this.delegateMoveRot = rot;
		this.delegateMoveScl = scl;
		this.delegateSetTrans = trans;
	}

	// Token: 0x0600034A RID: 842 RVA: 0x0001539C File Offset: 0x0001359C
	public void SetSphereColor(Color color)
	{
		this.sphere.SetBaseColor(color);
	}

	// Token: 0x040002D8 RID: 728
	private GuideDrive[] drives;

	// Token: 0x040002D9 RID: 729
	[SerializeField]
	private float checkDis = 100f;

	// Token: 0x040002DA RID: 730
	[SerializeField]
	private float scaleRate = 1f;

	// Token: 0x040002DB RID: 731
	[SerializeField]
	private GuideDrive_Inactive sphere;

	// Token: 0x040002DC RID: 732
	public Transform posRoot;

	// Token: 0x040002DD RID: 733
	public Transform rotRoot;

	// Token: 0x040002DE RID: 734
	public Transform sclRoot;

	// Token: 0x040002DF RID: 735
	[SerializeField]
	private GuideDrive_Pos[] drivePos;

	// Token: 0x040002E0 RID: 736
	[SerializeField]
	private GuideDrive_Pos[] drivePlane;

	// Token: 0x040002E1 RID: 737
	[SerializeField]
	private GuideDrive_Rot[] driveRot;

	// Token: 0x040002E2 RID: 738
	[SerializeField]
	private GuideDrive_Scl[] driveScl;

	// Token: 0x040002E6 RID: 742
	private Transform target;

	// Token: 0x040002E7 RID: 743
	private GuideDrive movingDrive;

	// Token: 0x040002E8 RID: 744
	private GuidesManager manager;

	// Token: 0x040002E9 RID: 745
	private bool isActive;

	// Token: 0x040002EA RID: 746
	public GuideDriveManager.DelegateMovePos delegateMovePos;

	// Token: 0x040002EB RID: 747
	public GuideDriveManager.DelegateMoveRot delegateMoveRot;

	// Token: 0x040002EC RID: 748
	public GuideDriveManager.DelegateMoveScl delegateMoveScl;

	// Token: 0x040002ED RID: 749
	public GuideDriveManager.DelegateSetTrans delegateSetTrans;

	// Token: 0x040002EE RID: 750
	public bool MoveInitiative = true;

	// Token: 0x02000064 RID: 100
	public struct CursorCheckData
	{
		// Token: 0x040002EF RID: 751
		public GuideDrive drive;

		// Token: 0x040002F0 RID: 752
		public float distance;

		// Token: 0x040002F1 RID: 753
		public Vector3 pos;
	}

	// Token: 0x02000065 RID: 101
	// (Invoke) Token: 0x0600034C RID: 844
	public delegate void DelegateMovePos(Vector3 move);

	// Token: 0x02000066 RID: 102
	// (Invoke) Token: 0x06000350 RID: 848
	public delegate void DelegateMoveRot(Quaternion move);

	// Token: 0x02000067 RID: 103
	// (Invoke) Token: 0x06000354 RID: 852
	public delegate void DelegateMoveScl(Vector3 move);

	// Token: 0x02000068 RID: 104
	// (Invoke) Token: 0x06000358 RID: 856
	public delegate void DelegateSetTrans(Vector3 pos, Quaternion rot, Vector3 scl);
}
